//
//  AppDelegate.m
//  YJRenter
//
//  Created by 文彬 on 2018/7/1.
//  Copyright © 2018年 文彬. All rights reserved.
//

#import "AppDelegate.h"
#import "HomeViewController.h"
#import "MessageViewController.h"
#import "OrderViewController.h"
#import "MineViewController.h"
#import "CYLTabBarController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController =[self getTabController];
    [self.window makeKeyAndVisible];
    
    [self setCommonStyle];
    
    
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

#pragma mark 功能函数
- (CYLTabBarController *)getTabController{
    
    HomeViewController *homeController = [[HomeViewController alloc]init];
    UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:homeController];
    
    MessageViewController *messageController = [[MessageViewController alloc]init];
    UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:messageController];
    
    OrderViewController *orderController = [[OrderViewController alloc]init];
    UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:orderController];
    
    MineViewController *mineController = [[MineViewController alloc]init];
    UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:mineController];
    
    CYLTabBarController *tabBarController = [[CYLTabBarController alloc] init];
    NSDictionary *dict1 = @{
                            CYLTabBarItemTitle : @"首页",
                            CYLTabBarItemImage : @"shouye2",
                            CYLTabBarItemSelectedImage : @"shoueye1",
                            };
    NSDictionary *dict2 = @{
                            CYLTabBarItemTitle : @"消息",
                            CYLTabBarItemImage : @"shouye2",
                            CYLTabBarItemSelectedImage : @"shoueye1",
                            };
    NSDictionary *dict3 = @{
                            CYLTabBarItemTitle : @"订单",
                            CYLTabBarItemImage : @"gouwuche2",
                            CYLTabBarItemSelectedImage : @"gouwuche1",
                            };
    NSDictionary *dict4 = @{
                            CYLTabBarItemTitle : @"我的",
                            CYLTabBarItemImage : @"wode2",
                            CYLTabBarItemSelectedImage : @"wode1",
                            };
    
    NSArray *tabBarItemsAttributes = @[ dict1, dict2,dict3,dict4 ];
    tabBarController.tabBarItemsAttributes = tabBarItemsAttributes;
    
    [tabBarController setViewControllers:@[nav1,nav2,nav3,nav4]];
    
    return tabBarController;
}

/**
 *  tabBarItem 的选中和不选中文字属性、背景图片
 */
- (void)setTabbarStyle {
    
    // 普通状态下的文字属性
    NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
    normalAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    
    // 选中状态下的文字属性
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSForegroundColorAttributeName] = [UIColor orangeColor];
    
    // 设置文字属性
    UITabBarItem *tabBar = [UITabBarItem appearance];
    [tabBar setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    [tabBar setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    
    // 设置背景图片
    UITabBar *tabBarAppearance = [UITabBar appearance];
    [tabBarAppearance setBackgroundColor:[UIColor whiteColor]];
}

- (void)setCommonStyle{
    //设置导航栏背景颜色和标题颜色
    [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
    //让导航栏颜色不增加系统自己的处理
    [UINavigationBar appearance].translucent = NO;
    
    //隐藏导航栏底部线条
    //    [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
    
    //系统的导航栏底部线条颜色太深  改成生产一张淡色图片
    [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setShadowImage:[StaticTools imageWithColor:kLineColor]];
    
    [[UINavigationBar appearance] setTitleTextAttributes:
     [NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],NSForegroundColorAttributeName,[UIColor blackColor],NSForegroundColorAttributeName,[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],NSForegroundColorAttributeName,[UIFont fontWithName:@"Arial-Bold" size:18],NSFontAttributeName,nil]];
    
    [self setTabbarStyle];
    
    if (@available(iOS 11, *)) { //http://www.jianshu.com/p/efbc8619d56b
        
        [UITableView appearance].estimatedRowHeight = 0;
        [UITableView appearance].estimatedSectionHeaderHeight = 0;
        [UITableView appearance].estimatedSectionFooterHeight = 0;
        
        [UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; //iOS11 解决SafeArea的问题，同时能解决pop时上级页面scrollView抖动的问题
    }
    
    
}



@end
